package com.vonchenchen.myslidingtabpager;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.vonchenchen.myslidingtabpager.holder.ViewHolder1;
import com.vonchenchen.myslidingtabpager.holder.ViewHolder2;
import com.vonchenchen.myslidingtabpager.holder.ViewHolder3;
import com.vonchenchen.myslidingtabpager.holder.ViewHolder4;
import com.vonchenchen.myslidingtabpager.ui.MySlidingTabPager;

import java.util.List;


public class MainActivity extends Activity {

    private MySlidingTabPager mMySlidingTabPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mMySlidingTabPager = (MySlidingTabPager) findViewById(R.id.mspg_main);
        initView();
    }

    private void initView(){
        //构造Tab
        TextView tab1 = new TextView(MainActivity.this);
        tab1.setText("TAB1");
        TextView tab2 = new TextView(MainActivity.this);
        tab2.setText("TAB2");
        TextView tab3 = new TextView(MainActivity.this);
        tab3.setText("TAB3");
        TextView tab4 = new TextView(MainActivity.this);
        tab4.setText("TAB4");
        //加入Tab
        mMySlidingTabPager.addTab(tab1);
        mMySlidingTabPager.addTab(tab2);
        mMySlidingTabPager.addTab(tab3);
        mMySlidingTabPager.addTab(tab4);
        //创建页面holder
        ViewHolder1 holder1 = new ViewHolder1();
        ViewHolder2 holder2 = new ViewHolder2();
        ViewHolder3 holder3 = new ViewHolder3();
        ViewHolder4 holder4 = new ViewHolder4();
        //加入页面holder
        mMySlidingTabPager.addHolder(holder1);
        mMySlidingTabPager.addHolder(holder2);
        mMySlidingTabPager.addHolder(holder3);
        mMySlidingTabPager.addHolder(holder4);

        //页面填充
        mMySlidingTabPager.start();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
